from .app import Flask


def register_blueprints(app):
    # 导入已创建蓝图
    from app.api.v1 import create_blueprint_v1
    # 注册蓝图到核心对象
    app.register_blueprint(create_blueprint_v1(), url_prefix='/v1')


def register_plugin(app):
    # 初始化db并注册到应用对象
    from app.models.base import db
    db.init_app(app)
    with app.app_context():
        db.create_all()


def create_app():
    """
    初始化应用核心对象
    :return:
    """
    app = Flask(__name__)
    # 导入配置文件
    app.config.from_object('app.config.secure')
    app.config.from_object('app.config.setting')
    # 导入扩展并注册
    register_blueprints(app)
    register_plugin(app)

    return app
